const puppeteer = require('puppeteer')
const config = require('./config')

async function start(skuId = 2316993) {

    const browser = await puppeteer.launch(
        {
            headless: false,
            // executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
            executablePath: config.chromiumPath
        }
    );
    const page = await browser.newPage();

    // page.on('console', msg => {
    //     for (let i = 0; i < msg.args().length; ++i)
    //         console.log(`${i}: ${msg.args()[i]}`);
    // });

    await page.goto(`https://item.jd.com/${skuId}.html`, {
        // waitUntil: ['networkidle0']
    });

    let {skuName,skuPrice} = await page.evaluate((skuId) => {
        return {
            skuName: document.querySelector(`.sku-name`).innerText,
            skuPrice: document.querySelector(`.J-p-${skuId}`).innerText
        }
    }, skuId)

    await browser.close();

    console.log(`${skuName}：${skuPrice}`)
}

start(2316993)